﻿@using Microsoft.AspNetCore.Components.Authorization
@inherits LayoutComponentBase

<MudDialogProvider />
<MudSnackbarProvider />
<MudPopoverProvider />
<MudThemeProvider @ref="@_mudThemeProvider" Theme="@CurrentTheme" IsDarkMode="@_defaultDarkMode" />

<MudLayout>
    <AuthorizeView>
        <Authorized>
            <MudAppBar Elevation="1">
                @* ReSharper disable once UnusedParameter.Local *@
                <MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@(e => DrawerToggle())" />
                <MudSpacer />
                <MudIconButton Icon="@Icons.Material.Filled.MoreVert" Color="Color.Inherit" Edge="Edge.End" />
            </MudAppBar>
            <MudDrawer @bind-Open="_drawerOpen" Elevation="2">
                <MudDrawerHeader>
                    <MudText Typo="Typo.h5" Class="mt-1">maERP</MudText>
                </MudDrawerHeader>
                <NavMenu />
            </MudDrawer>
            <MudMainContent>
                <MudContainer Class="mt-12 px-8" MaxWidth="MaxWidth.False">
                    @Body
                </MudContainer>
            </MudMainContent>
        </Authorized>
        <NotAuthorized>
            <MudContainer MaxWidth="MaxWidth.ExtraSmall" Class="d-flex align-center" Style="height: 100vh;">
                <MudPaper Elevation="25" Class="pa-8" Width="100%" MaxWidth="500px">
                    @Body
                </MudPaper>
            </MudContainer>
        </NotAuthorized>
    </AuthorizeView>
</MudLayout>

@code {
    bool _drawerOpen = true;

    void DrawerToggle()
    {
        _drawerOpen = !_drawerOpen;
    }
}